use anyhow::Result;
use clap::Parser;
use tracing::{info, Level};
use tracing_subscriber;

mod app;

use app::CdbStudioApp;

#[derive(Parser)]
#[command(name = "cdb-studio")]
#[command(about = "AI-powered database management platform")]
#[command(version)]
struct Cli {
    /// Enable debug logging
    #[arg(short = 'd', long)]
    debug: bool,

    /// Configuration file path
    #[arg(short = 'c', long)]
    config: Option<String>,

    /// Database connection string
    #[arg(short = 'b', long)]
    database: Option<String>,
}

fn main() -> Result<()> {
    let cli = Cli::parse();

    // Initialize logging
    let log_level = if cli.debug { Level::DEBUG } else { Level::INFO };
    tracing_subscriber::fmt()
        .with_max_level(log_level)
        .with_target(false)
        .init();

    info!("Starting CDB Studio v{}", env!("CARGO_PKG_VERSION"));

    // Load configuration
    let config_path = cli.config.unwrap_or_else(|| "config/default.toml".to_string());
    info!("Loading configuration from: {}", config_path);

    // Run the application
    CdbStudioApp::run()?;

    Ok(())
}
